# cmake_minimum_required(VERSION 3.16)



# set(CMAKE_AUTOUIC ON)
# set(CMAKE_AUTOMOC ON)
# set(CMAKE_AUTORCC ON)
 set(CMAKE_CXX_STANDARD 23)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network DBus )
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core SerialBus DBus )

add_library(XYmodbus STATIC
    XYmodbus.cpp
    XYmodbus.ixx
)

target_link_libraries(XYmodbus PRIVATE
    Qt${QT_VERSION_MAJOR}::Core
    Qt6::SerialBus
    Qt${QT_VERSION_MAJOR}::Network
    Qt${QT_VERSION_MAJOR}::DBus)

target_compile_definitions(XYmodbus PRIVATE MODBUS_LIBRARY)
# 启用SKIP_AUTOMOC选项，避免为模块接口文件生成MOC文件moc 手动生成
#globaldata.ixx -o moc_globaldata.cpp
#并在globaldata.cpp的最后添加 #include "globaldata.moc"
set_source_files_properties(XYmodbus.ixx PROPERTIES SKIP_AUTOMOC ON)

# SHARED共享库需要导出符号
#set_target_properties(Modbus PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)

# 如果有头文件需要暴露给主项目
#target_include_directories(mymodule INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
#以下为STATIC静态库需要安装模块在正常的位置
# 设置输出目录以确保模块文件放置在正确位置
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
install(DIRECTORY ${CMAKE_BINARY_DIR}/XYmodules/
    DESTINATION ${CMAKE_INSTALL_PREFIX}/include/XYmodules
)
